package com.water.controller.wx;

import com.water.service.SyMenuService;
import com.water.service.wx.Wx_UserService;
import com.water.utils.RandNum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

@RequestMapping("wx")
@Controller
public class Wx_UserApi {

  @Autowired
  Wx_UserService wx_userService;

    /**
     * 注册
     * @param map
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "registerUser",method = RequestMethod.POST)
    public String registerUser(@RequestBody Map map){
        System.out.println(map.toString());
map.put("uid", RandNum.getGUID());
int n=wx_userService.insertUser(map);
        System.out.println(n);
if(n==0){
    return "failure";
}
        return "success";
    }

    /**
     * 登录
     * @param map
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "userLogin",method = RequestMethod.POST)
    public String userLogin(@RequestBody Map map){
        System.out.println(map.toString());
        String uid=wx_userService.findByUidPhonePwd(map);
        if(uid!=null){
            return uid;
        }
        return "failure";
    }


    @ResponseBody
    @RequestMapping(value = "/",method = RequestMethod.GET)
    public String test(){
        return "test";
    }
}